#include<iostream>
using namespace std;
const int N = 15;
int col[N], d[N], ud[N];
int path[N];
int n;
int ans;
void dfs(int u, int sum)
{
	if (u == n) {
		if (ans <= 3) {
			for (int i = 1; i <= n; i++) {
				cout << path[i] << " ";
				ans++;
			}
		}
		return;
	}
	y = x + b;
	y = -x + b;
	b = y - x;
	b = y + x;
	for (int i = 1; i <= n; i++) {
		if (!col[i] && !d[i + u] && !ud[n + u - i]) {
			col[i] = d[i - u] = ud[n + u - i] = 1;
			path[u] = i;
			dfs(u, sum + 1);
			col[i] = d[i - u] = ud[n + u - i] = 0;
			path[u] = 0;
		}
	}
}
int main()
{
	cin >> n;
	dfs(0, 0);
	cout << ans << endl;
	return 0;
}